home *** CD-ROM | disk | FTP | other *** search
- --------------------------------------------------------------------------------
- -- Weapon Arrow Rain + Projectile Arrow
- -- Original Carnage Contest Weapon
- -- Script by DC, August 2009, www.UnrealSoftware.de
- --------------------------------------------------------------------------------
-
- -- Setup Tables
- if cc==nil then cc={} end
- cc.arrowrain={}
- cc.arrowrain.arrow={}
-
- -- Load & Prepare Ressources
- cc.arrowrain.gfx_wpn=loadgfx("weapons/arrowrain.png") -- Weapon Image
- setmidhandle(cc.arrowrain.gfx_wpn)
- cc.arrowrain.gfx_pro=loadgfx("weapons/arrow.bmp") -- Projectile Image
- setmidhandle(cc.arrowrain.gfx_pro)
- cc.arrowrain.sfx_attack=loadsfx("arrow_shoot.ogg") -- Attack Sound
- cc.arrowrain.sfx_impact=loadsfx("arrow_impact.ogg") -- Impact Sound
-
- --------------------------------------------------------------------------------
- -- Weapon: Arrow Rain
- --------------------------------------------------------------------------------
-
- cc.arrowrain.id=addweapon("cc.arrowrain","Arrow Rain",cc.arrowrain.gfx_wpn,0,3) -- Add Weapon (0 uses, first in round 3)
-
- function cc.arrowrain.draw() -- Draw
- -- Fade Dark
- if weapon_shots>0 and weapon_timer<0.4 then
- weapon_timer=weapon_timer+0.01
- end
- end
-
- function cc.arrowrain.attack(attack) -- Attack
- if (weapon_shots<=0) and (attack==1) then
- -- No more weapon switching!
- useweapon(0)
- weapon_shots=weapon_shots+1
- -- Random Seed
- math.randomseed(getplayerx(0)*374+getplayery(0)*56+getframe()*123+getround()*98)
- -- Spawn Arrows (amount depending on map size)
- limit=math.ceil(getmapwidth()/4)
- if limit>500 then
- limit=500
- end
- for i=1,limit,1 do
- pid=createprojectile(cc.arrowrain.arrow.id)
- projectiles[pid]={}
- projectiles[pid].x=math.random(0,getmapwidth())
- projectiles[pid].y=-math.random(500,650)
- projectiles[pid].sx=math.random(-40,40)*0.1
- projectiles[pid].sy=math.random(150,200)*0.1
- projectiles[pid].timer=i*math.random(2,3)
- end
- -- End Turn
- endturn()
- end
- end
-
- --------------------------------------------------------------------------------
- -- Projectile: Arrow
- --------------------------------------------------------------------------------
-
- cc.arrowrain.arrow.id=addprojectile("cc.arrowrain.arrow") -- Add Projectile
-
- function cc.arrowrain.arrow.draw(id) -- Draw
- setbgcolor(0,0,0,weapon_timer,0.01)
- if projectiles[id].timer<=0 then
- -- Setup draw mode
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- setscale(1,1)
- -- Calculate projectile rotation
- setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
- -- Draw projectile
- drawimage(cc.arrowrain.gfx_pro,projectiles[id].x,projectiles[id].y)
- end
- end
-
- function cc.arrowrain.arrow.update(id) -- Update
- -- Timer
- if projectiles[id].timer>0 then
- -- Count Down before arrow appears
- projectiles[id].timer=projectiles[id].timer-1
- if projectiles[id].timer==0 then
- playsound(cc.arrowrain.sfx_attack)
- end
- else
- rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
- -- Wind + Gravity influence on speed
- projectiles[id].sx=projectiles[id].sx+getwind()*0.1
- projectiles[id].sy=projectiles[id].sy+getgravity()*1.5
- -- Move (in substep loop for optimal collision precision)
- msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
- msubx=projectiles[id].sx/msubt
- msuby=projectiles[id].sy/msubt
- for i=1,msubt,1 do
- projectiles[id].x=projectiles[id].x+msubx
- projectiles[id].y=projectiles[id].y+msuby
- -- Collision
- if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)==1 then
- if playercollision()~=0 then
- -- Cause Player damage
- playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
- playerdamage(playercollision(),15)
- blood(projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)
- playsound(sfx_splatter3)
- elseif objectcollision()~=0 then
- -- Cause Object damage
- objectdamage(objectcollision(),15)
- else
- -- Draw Arrow in terrain
- terrainimage(cc.arrowrain.gfx_pro,projectiles[id].x,projectiles[id].y,0,rot)
- end
- -- Effects
- playsound(cc.arrowrain.sfx_impact)
- particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*8,projectiles[id].y-math.cos(math.rad(rot))*8)
- particlefadealpha(0.006)
- -- Free projectile
- freeprojectile(id)
- return 1
- end
- -- Water
- if (projectiles[id].y)>getwatery()+5 then
- -- Effects
- particle(p_waterhit,projectiles[id].x,projectiles[id].y)
- if math.random(1,2)==1 then
- playsound(sfx_hitwater2)
- else
- playsound(sfx_hitwater3)
- end
- -- Free projectile
- freeprojectile(id)
- return 1
- end
- end
- end
- end